package com.llyb.config;

import com.llyb.inter.ChatAssistant;
import com.llyb.service.InvoiceHandler;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.request.json.JsonObjectSchema;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.tool.ToolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

@Configuration
public class LLMConfig {

    @Bean
    public ChatModel chatModel(){
        return OpenAiChatModel.builder().
                apiKey(System.getenv("aliQwen-api")).
                modelName("qwen-plus").
                baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1").
                build();
    }


/*    @Bean
    public ChatAssistant chatAssistant(ChatModel chatModel){

        ToolSpecification toolSpecification = ToolSpecification.builder().
                name("开发票助手").
                description("根据用户提供的信息，开具发票").
                parameters(JsonObjectSchema.builder().
                        addStringProperty("companyName", "公司名称").
                        addStringProperty("dutyNumber", "税序列号").
                        addStringProperty("amount", "开票金额，保留两位小数").
                        build())
                .build();


        ToolExecutor toolExecutor = (toolExecutionRequest,memoryId)->{
            System.out.println(toolExecutionRequest.id());
            System.out.println(toolExecutionRequest.name());
            String arguments1 = toolExecutionRequest.arguments();
            System.out.println("arguments1 -------" + arguments1);
            return "开具成功";
        };

        return AiServices.builder(ChatAssistant.class).
                chatModel(chatModel).
                tools(Map.of(toolSpecification,toolExecutor)).
                build();
    }*/

    @Bean
    public ChatAssistant chatAssistant(){

        return AiServices.builder(ChatAssistant.class).
                chatModel(chatModel()).
                tools(new InvoiceHandler()).
                build();
    }

}